package com.group.controller;


import com.group.pojo.Product;
import com.group.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author group
 * @since 2021-09-06
 */
@Controller
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("selectProductList")
    @ResponseBody
    public List<Product> selectProductList(Product product){
        List<Product> list=productService.selectProductList(product);
        return list;
    }

    @GetMapping("findProductById")
    @ResponseBody
    public Product findProductById(Integer id){
        Product product=productService.findProductById(id);
        return product;
    }

    @GetMapping("productClassification")
    @ResponseBody
    public List<Product> productClassification(String type){
        List<Product> list=productService.productClassification(type);
        return list;
    }
    @ResponseBody
    @PostMapping("addProduct")
    public boolean addProduct(@RequestBody Product product){
        boolean flag=productService.addProduct(product);
        if(flag){
            return true;
        }else{
            return false;
        }
    }

    @GetMapping("updateProduct")
    @ResponseBody
    public boolean updateProduct(Product product){
        boolean flag=productService.updateProduct(product);
        if(flag){
            return true;
        }else{
            return false;
        }
    }

    @GetMapping("deleteProducts")
    @ResponseBody
    public boolean deleteProducts(int[] ids){
        boolean flag=productService.deleteProducts(ids);
        if(flag){
            return true;
        }else{
            return false;
        }
    }
}

